<?php
require 'inc_security.php';
$list = new dataGrid('cat_id',30);
$list->add('cat_name','Tên danh mục','string',1,1);
$list->add('cat_order','Thứ tự','string',0,1);
$list->add('','Xuất bản','string');
$list->add('','Sửa','edit');
$list->add('','Xóa','delete');
$arrCat = $catBase->list_categories(0,'cat_active = 1 AND cat_type = "'.$cat_type.'" '. $list->sqlSearch(),'cat_id,cat_parent_id,cat_order,cat_active,cat_name,cat_type,lang_id',$list->sqlSort().'lang_id ASC,cat_order ASC,cat_id ASC');
$db_count = new db_count('SELECT count(*) as count
                            FROM '.$bg_table.'
                            WHERE 1 AND cat_type = "'.$cat_type.'" '.$list->sqlSearch().'
                            ');
$total = $db_count->total;unset($db_count);
$list->total_record = $total;
$total_row = $total;
$list_cat = array();
foreach($arrCat as $i=>$cat){
    $tt = '';
    for($j=0;$j<$cat["level"];$j++) $tt .= '|--';
    $list_cat[$cat["cat_id"]]['cat_name'] = $tt . $cat["cat_name"];
    $list_cat[$cat['cat_id']]['cat_type'] = $cat['cat_type'];
    $list_cat[$cat['cat_id']]['cat_order'] = $cat['cat_order'];
    $list_cat[$cat['cat_id']]['cat_active'] = $cat['cat_active'];
    $list_cat[$cat['cat_id']]['cat_parent_id'] = $cat['cat_parent_id'];
    $list_cat[$cat['cat_id']]['lang_id'] = $cat['lang_id'];
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?=$load_header?>
</head>
<body>
<div class="module_header bold fix"><?=$module_name?></div>
<div id="wrapper">
    <?=$list->showHeader($total_row)?>
    <?php
    $i = 0;
    ?>
    <?php foreach($list_cat as $key=>$value){
        $i++;
        ?>
        <?=$list->start_tr($i,$key)?>
        <td class="center"><span class="span3" style="text-align:left;padding-left:30px"><?=$value['cat_name']?></span></td>
        <td class="center"><?=form_input('cat_order'.$key,$value['cat_order'],'style="width:30px;text-align:center" onkeyup="check_edit(\'record_'.$i.'\')"')?></td>
        <?=$list->showCheckbox('cat_active',$value['cat_active'],$key)?>
        <?=$list->showEdit($key)?>
        <?=$list->showDelete($key)?>
        <?=$list->end_tr()?>
    <?}?>
    <?=$list->showFooter()?>
</div>
</body>
</html>